package com.ruoyi.pg.questionnaire.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.pg.answerSheet.service.IPgAnswerService;
import com.ruoyi.pg.questionnaire.domain.PgSurvey;
import com.ruoyi.pg.questionnaire.vo.PgSurveyVo;
import com.ruoyi.pg.questionnaire.mapper.PgSurveyMapper;
import com.ruoyi.pg.questionnaire.service.IPgSurveyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 问卷Service业务层处理
 *
 * @author Ming
 * @date 2025-08-22
 */
@Service
public class PgSurveyServiceImpl extends ServiceImpl<PgSurveyMapper, PgSurvey> implements IPgSurveyService {

    @Autowired
    private IPgAnswerService answerService;

    @Override
    public TableDataInfo<PgSurveyVo> queryList(PgSurveyVo entity) {
        return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
    }

    @Override
    public List<PgSurveyVo> queryAll(PgSurveyVo entity) {
        List<PgSurveyVo> pgSurveyVos = this.baseMapper.queryList(entity);
        for (PgSurveyVo pgSurveyVo : pgSurveyVos) {
            if (!pgSurveyVo.getTitle().contains("老年人能力最终等级"))
                pgSurveyVo.setIfComplete(answerService.ifCompleteBySurveyId(pgSurveyVo.getId(), entity.getAssId()));
        }
        return pgSurveyVos;
    }

    @Override
    public PgSurveyVo queryById(Long id) {
        return this.baseMapper.queryById(id);
    }

    @Override
    public Long selectIdByTempId(Long tempId) {
        return baseMapper.selectIdByTempId(tempId);
    }
}
